package com.bw.zg3park2212.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.base.entity.GgcommentEntity
import com.bw.base.entity.GgcommentEntityItem
import com.bw.base.entity.SendgonggEntity
import com.bw.base.entity.SendgonggParam
import com.bw.base.mvvm.BaseViewModel
import com.bw.base.net.ApiService
import com.google.gson.Gson
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class HomeViewModel@Inject constructor(val apiService: ApiService):BaseViewModel() {
    var ggSuccse=MutableLiveData<GgcommentEntity>()
    fun getGg(page:Int,size:Int){
        httpRequst(
            { apiService.getGg(page,size)},
            ggSuccse::postValue
        )
    }
    var sendggSuccse=MutableLiveData<GgcommentEntityItem>()
//    fun sendGg(body:SendgonggParam){
//        httpRequst(
//            {
//                apiService.sendGg(body)},
//            sendggSuccse::postValue
//        )
//    }
fun sendGg(content:String,publishTime:String,title:String){
        httpRequst(
            {
                var map= mutableMapOf<String,Any>()
                map.put("content",content)
                map.put("id",0)
                map.put("publishTime",publishTime)
                map.put("status","")
                map.put("title",title)
                map.put("type","")
                map.put("userId",0)
                var josn=Gson().toJson(map)
                var body=RequestBody.create(
                    "application/json;charset=utf-8".toMediaTypeOrNull(),josn
                )
                apiService.sendGg(body)
            },
            sendggSuccse::postValue
        )
    }
}